<?php
namespace Home\Controller;

use Think\Controller;

/**
*@desc 服务商后台
*/
class WorksorderController extends CommonController {
    private $auth_status = 0;//默认：未认证
    private $user_email = null;//用户邮箱
    private $uid = null;
    private $auth_type = 1;
    private $user_name = '';
    private $white_list = array('shipeng.hou@37degree.com');

    public function __construct(){
        //是否服务商用户，且登录状态
        parent::__construct();

		//判断用户是否服务商用户
        // if($this->role==1){
        //     redirect('/Index/index');
        // }
        
        $this->getAuthStatus();
        $this->auth_status = session('37degree_auth_status');
        
        $this->user_email = session('user_email');
        $this->uid = session('uid');
        $this->auth_type = session('auth_type');
        $this->user_name = session('user_name');

        $this->assign('user_email',$this->user_email);
        if(empty($this->uid)) redirect('/member/login.html');
    }


    //订单列表
    public function orderlist(){
        $this->assign('head_title','我的订单－云途数据市场');
        $this->display("list");
    }

    //订单详情
    public function info (){
        if(empty($this->uid)) redirect('/member/login.html');

        $order_id = I('get.order',null);
        // $order_id = "f986898170f43158e3092768400cbb98";//test

        $info = array();
        $full_package_name = $limit_num = $price = "";
        if(!empty($order_id)){
            $orderModel = D('Order');
            $info = $orderModel->getInfo($order_id,true);

            if(!empty($info)){
                $condition_json = json_decode($info['condition_json'],true);
                $price = $condition_json['package_price'];
                $full_package_name = "¥".$price."/".$condition_json['package_cycle'];
                $limit_num = $condition_json['limit_num'];
            }
            $info['new_conditon_json'] = $condition_json;
            $info['price'] = $price;
            $info['full_package_name'] = $full_package_name;
            $info['new_limit_num'] = $limit_num;
        }

        $this->assign('info',$info);
        $this->assign('head_title','订单详情－云途数据市场');
        $this->display();
    }

    //ajax获取订单列表数据
    public function ajaxOrderList(){
        $page = I('post.page',1,'intval');
        $pagesize = I('post.pagesize',20,'intval');
        $type = I('post.type','all');

        $enable = 1;$pay_status = null;
        switch($type){
            case 'pendingpay':
                $pay_status = array(0,-1);
                break;
            case 'alreadypay':
                $pay_status = array(1,2);
                break;
            case 'disable':
                $enable = 0;
                break;
            default:
                $pay_status = null;
                break;
        }

        //是否登录
        if(empty($this->uid)){
            // $this->ajaxReturn( array('status'=>4001,'msg'=>'请登录','data'=>null) );
        }

        //搜索条件
        $order_no = trim(I('post.order_id',null));
        $start_date = I('post.start_date',null);
        $end_date = I('post.end_date',null);
        if(!empty($start_date)){
            $start_date = strtotime($start_date) - 1;
        }
        if(!empty($end_date)){
            $end_date = strtotime($end_date) + 24*3600 -1;
        }

        $orderModel = D('Order');
        $list = $orderModel->getListWithWorks($this->uid,$pay_status,$enable,$order_no,$start_date,$end_date,$page,$pagesize);

        $this->ajaxReturn( array('status'=>200,'msg'=>'OK','data'=>$list) );
    }

}
